<!-- 详情 -->
<template>
    <div class="drawer-layout">
      <el-drawer
        :title="ConfigTitle"
        :visible.sync="drawer"
        @closed="closedinvitation"
        size="70%"
        :wrapperClosable="false"
      >
        <div class="layout">
          <el-form
            label-position="left"
            :inline="true"
            size="small"
            ref="eventsForm"
            :model="eventsForm"
          >
            <el-alert
              v-if="ConfigTitle == '禁用对象'"
              style="margin-bottom: 20px"
              title="禁用对象是指禁止参与该活动的用户"
              type="warning"
              :closable="false"
            ></el-alert>
            <el-alert
              v-else
              style="margin-bottom: 20px"
              title="重复对象是指以下用户正在同时参与其他抽奖活动，暂无法参与该抽奖活动；需等当前抽奖活动结束后才可参与该抽奖活动；可以对重复用户进行禁用处理，即不能参与该抽奖活动"
              type="warning"
              :closable="false"
            ></el-alert>
            <div class="configform-box">
              <el-form-item
                label="用户昵称"
                class="form-box-item"
                prop="activity_name"
              >
                <el-input
                  clearable
                  placeholder="请输入用户昵称"
                  v-model="eventsForm.activity_name"
                >
                </el-input>
              </el-form-item>
              <el-form-item
                label="用户地区"
                class="form-box-item"
                prop="appoint_area_select"
              >
                <el-cascader
                  filterable
                  v-model="eventsForm.appoint_area_select"
                  style="width: 100%"
                  :options="regionList"
                  collapse-tags
                  :props="{
                    expandTrigger: 'hover',
                    multiple: true,
                    value: 'id',
                    label: 'name',
                    children: 'children',
                    checkStrictly: false,
                    emitPath: false,
                  }"
                  clearable
                ></el-cascader>
              </el-form-item>
              <el-form-item
                label="用户群组"
                class="form-box-item"
                prop="appoint_group_select"
              >
                <el-select
                  v-model="eventsForm.appoint_group_select"
                  multiple
                  clearable
                  collapse-tags
                  placeholder="请选用户分组"
                >
                  <el-option
                    v-for="item in groupingList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                label="用户等级"
                class="form-box-item"
                prop="appoint_level_select"
              >
                <el-select
                  v-model="eventsForm.appoint_level_select"
                  multiple
                  clearable
                  collapse-tags
                  placeholder="请选用户等级"
                >
                  <el-option
                    v-for="item in gradeList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                label="用户标签"
                class="form-box-item"
                prop="appoint_tag_select"
              >
                <el-select
                  clearable
                  style="width: 100%"
                  v-model="eventsForm.appoint_tag_select"
                  multiple
                  collapse-tags
                  placeholder="请选择标签"
                >
                  <el-option-group
                    v-for="group in TagCategoryAll"
                    :key="group.category_name"
                    :label="group.category_name"
                  >
                    <el-option
                      v-for="item in group.child"
                      :key="item.id"
                      :label="item.tag_name"
                      :value="item.id"
                    >
                    </el-option>
                  </el-option-group>
                </el-select>
              </el-form-item>
              <el-form-item label="用户会员" class="form-box-item" prop="card_id">
                <el-select
                  v-model="eventsForm.card_id"
                  multiple
                  collapse-tags
                  clearable
                  placeholder="请选用户会员"
                >
                  <el-option
                    v-for="item in vipCard"
                    :key="item.id"
                    :label="item.card_name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="用户状态" class="form-box-item" prop="status">
                <el-select
                  clearable
                  v-model="eventsForm.status"
                  placeholder="请选择状态"
                >
                  <el-option
                    v-for="item in [
                      { id: 1, name: '正常' },
                      { id: 0, name: '禁用' },
                      { id: 2, name: '预注销用户' },
                    ]"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" style="height: 30px" @click="getList"
                  >查询</el-button
                >
                <el-button style="height: 30px" @click="resetForm('eventsForm')"
                  >重置</el-button
                >
                <el-button
                  v-if="ConfigTitle == '黑名单'"
                  type="primary"
                  style="height: 30px"
                  @click="Batchdeletion('1')"
                  >批量移出黑名单</el-button
                >
                <el-button
                  v-else
                  type="primary"
                  style="height: 30px"
                  @click="Batchdeletion('2')"
                  >批量禁用</el-button
                >
              </el-form-item>
            </div>
            <div class="configform-box">
              <div>
                <el-table
                  ref="UnselectedRowKey"
                  v-loading="loading"
                  highlight-current-row
                  :data="dataList"
                  :header-cell-style="{
                    'background-color': '#f3f8fe',
                    color: '#606266',
                    height: '50px',
                  }"
                  style="width: 100%"
                  :row-key="getUnselectedRowKeys"
                  @selection-change="handleSelectionChange"
                >
                  <el-table-column
                    :reserve-selection="true"
                    type="selection"
                    width="55"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    prop="id"
                    label="用户id"
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    prop="nickname"
                    label="用户昵称"
                  ></el-table-column>
                  <el-table-column align="center" prop="region" label="用户区域">
                    <template slot-scope="scope">
                      {{
                        scope.row.province_name ? scope.row.province_name : "-"
                      }}
                      {{ scope.row.city_name ? scope.row.city_name : "-" }}
                    </template>
                  </el-table-column>
                  <el-table-column
                    width="200"
                    align="center"
                    prop="group"
                    label="用户群组"
                  >
                    <template slot-scope="scope">
                      <!-- 用户群组：提示多个群组需要用分隔符区分，‘空格’+‘/’,超过三个显示超过的数量 -->
                      <el-tooltip
                        class="item"
                        effect="dark"
                        :content="scope.row.group_name"
                        placement="top"
                      >
                        <div
                          v-if="scope.row.group_name"
                          style="display: flex; justify-content: center"
                        >
                          <div>{{ scope.row.group_name }}</div>
                        </div>
                      </el-tooltip>
                      <div v-if="!scope.row.group_name">-</div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    width="200"
                    align="center"
                    prop="tag"
                    label="用户标签"
                  >
                    <template slot-scope="scope">
                      <el-tooltip
                        class="item"
                        effect="dark"
                        :content="scope.row.tag_name.join('/')"
                        placement="top"
                      >
                        <div
                          v-if="scope.row.tag_name.length !== 0"
                          style="display: flex; justify-content: center"
                        >
                          <div
                            v-if="index < 3"
                            v-for="(item, index) in scope.row.tag_name"
                            :key="index"
                          >
                            {{ item }} /
                          </div>
                          <div
                            v-if="scope.row.tag_name.length > 3"
                            class="table-num"
                          >
                            + {{ scope.row.tag_name.length }}
                          </div>
                        </div>
                      </el-tooltip>
                      <div v-if="scope.row.tag_name.length == 0">-</div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="status"
                    label="参与状态"
                  ></el-table-column>
                  <el-table-column label="操作" fixed="right">
                    <template slot-scope="scope">
                      <el-button
                        type="text"
                        v-if="ConfigTitle == '黑名单'"
                        @click="deletion(scope.row, '1')"
                      >
                        移除黑名单
                      </el-button>
                      <el-button
                        type="text"
                        v-else
                        @click="deletion(scope.row, '2')"
                      >
                        加入黑名单
                      </el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <pagination
                  v-show="total > 0"
                  :total="total"
                  :page.sync="eventsForm.page"
                  :limit.sync="eventsForm.count"
                  @pagination="getList"
                />
              </div>
            </div>
          </el-form>
        </div>
      </el-drawer>
    </div>
  </template>
  <script>
  import { getClubCardList } from "@/api/finance/index";
  import { rangeHasJoinUserList, rangeBlackUserList } from "@/api/index";
  export default {
    name: "detail",
    props: [
      "ConfigTitle",
      "userIds",
      "groupingList",
      "TagCategoryAll",
      "gradeList",
      "regionList",
      "ConfigTitle",
    ],
    components: {},
  
    data() {
      return {
        drawer: true,
        activeName: "first",
        vipCard: [], // 会员卡列表
        // 筛选条件
        eventsForm: {
          activity_type: 10001,
          remove_activity_id: "",
          appoint_area_select: [],
          appoint_level_select: [],
          appoint_group_select: [],
          appoint_tag_select: [],
          user_black: [],
          nickname: "",
          user_status: [],
          card_id: [],
          page: 1,
          count: 10,
        },
        loading: false,
        dataList: [], // 筛选之后的列表
        total: 0, // 筛选之后的列表总条数
        dialogTableVisible: false,
        multipleSelection: [],
      };
    },
    mounted() {
      this.loading = true;
      getClubCardList().then((res) => {
        if (res.code !== 200 || res.status !== 1) {
          return this.$messages.error(res.msg);
        }
        this.vipCard = res.data.list;
        this.getList();
      });
    },
    methods: {
      getList(userId) {
        this.loading = true;
        if (Array.isArray(userId)) {
          this.userIds = userId;
        }
        if (this.ConfigTitle == "重复对象") {
          //调用重复对象接口
          this.getRepeat();
        } else {
          // 调用黑名单接口
          this.getBlacklist();
        }
      },
      //调用重复对象接口
      getRepeat() {
        let screenForm = {
          activity_type: this.eventsForm.activity_type,
          appoint_area_select: this.eventsForm.appoint_area_select.toString(),
          remove_activity_id: this.eventsForm.remove_activity_id.toString(),
          appoint_level_select: this.eventsForm.appoint_level_select.toString(),
          appoint_group_select: this.eventsForm.appoint_group_select.toString(),
          appoint_tag_select: this.eventsForm.appoint_tag_select.toString(),
          user_black: this.userIds.toString(),
          nickname: this.eventsForm.nickname,
          user_status: this.eventsForm.user_status.toString(),
          card_id: this.eventsForm.card_id.toString(),
          page: this.eventsForm.page,
          count: this.eventsForm.count,
        };
        rangeHasJoinUserList(screenForm).then((res) => {
          this.loading = false;
          if (res.code !== 200 || res.status !== 1) {
            this.$messages.error(res.msg);
            return;
          }
          this.dataList = res.data.list;
          this.total = res.data.total;
          this.$refs.UnselectedRowKey.clearSelection();
        });
      },
      // 调用黑名单接口
      getBlacklist() {
        let screenForm = {
          activity_type: this.eventsForm.activity_type,
          appoint_area_select: this.eventsForm.appoint_area_select.toString(),
          remove_activity_id: this.eventsForm.remove_activity_id.toString(),
          appoint_level_select: this.eventsForm.appoint_level_select.toString(),
          appoint_group_select: this.eventsForm.appoint_group_select.toString(),
          appoint_tag_select: this.eventsForm.appoint_tag_select.toString(),
          user_black: this.userIds.toString(),
          nickname: this.eventsForm.nickname,
          user_status: this.eventsForm.user_status.toString(),
          card_id: this.eventsForm.card_id.toString(),
          page: this.eventsForm.page,
          count: this.eventsForm.count,
        };
        rangeBlackUserList(screenForm).then((res) => {
          this.loading = false;
          if (res.code !== 200 || res.status !== 1) {
            this.$messages.error(res.msg);
            return;
          }
          this.dataList = res.data.list;
          this.total = res.data.total;
          this.$refs.UnselectedRowKey.clearSelection();
        });
      },
      // 关闭抽屉
      closedinvitation() {
        this.$parent.closeConfig();
      },
  
      //重置
      resetForm(formName) {
        this.$refs[formName].resetFields();
        this.getList();
      },
      //多选
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      //批量
      Batchdeletion(type) {
        if (this.multipleSelection.length == 0) {
          this.$alert("请选择用户", "提示", {
            confirmButtonText: "确定",
            callback: (action) => {},
          });
        } else {
          if (type == "1") {
            this.$parent.removeBlacklist(this.multipleSelection);
          } else {
            this.$parent.joinblack(this.multipleSelection);
            this.$refs.UnselectedRowKey.clearSelection();
          }
        }
      },
      deletion(row, type) {
        if (type == "1") {
          this.$parent.removeBlacklist([row]);
        } else {
          this.$parent.joinblack([row]);
        }
      },
      // 商户列表每一条的key
      getUnselectedRowKeys(row) {
        return row.id;
      },
    },
  };
  </script>
  <style lang="scss">
  .drawer-layout {
    /*1.显示滚动条：当内容超出容器的时候，可以拖动：*/
    .el-drawer__body {
      overflow: auto;
    }
  
    /*2.隐藏滚动条，太丑了*/
    .el-drawer__container ::-webkit-scrollbar {
      display: none;
    }
  
    .el-drawer__header {
      background-color: #409eff;
      color: #ffffff;
      padding: 10px 20px;
      margin-bottom: 10px;
    }
  
    .el-tabs__header {
      padding-left: 50px;
      margin: 0;
    }
  
    .el-tabs__item {
      padding: 0 40px;
    }
  
    .el-tabs__nav-wrap::after {
      content: "";
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 2px;
      background-color: #ffffff;
      z-index: 1;
    }
  
    .el-alert--warning.is-light .el-alert__description {
      color: #c77b04;
      font-size: 14px;
    }
  
    .configform-box {
      .form-box-item {
        .el-form-item__label {
          font-size: 12px;
          font-weight: 500;
          width: 80px;
        }
  
        .el-input {
          width: 200px;
        }
      }
    }
  }
  </style>
  <style lang="scss" scoped>
  .blockquote-box {
    border-left: 4px solid #409eff;
    padding-left: 16px;
    margin: 16px 0;
    height: 40px;
    line-height: 40px;
    background: #fafafa;
    font-size: 16px;
  }
  
  .configform-box {
    margin: 0 20px;
  
    .form-box-item {
      padding-bottom: 10px;
      padding-right: 20px;
      font-size: 12px;
      color: #4c4c4c;
  
      .form-tip {
        font-size: 12px;
        color: #4c4c4c;
  
        .tip-key {
          font-weight: bold;
          text-decoration: underline;
        }
      }
    }
  
    .table-top {
      display: flex;
      justify-content: space-between;
      margin-bottom: 20px;
  
      .table-top-left {
        display: flex;
  
        div {
          margin-right: 20px;
        }
      }
  
      .table-top-right {
        display: flex;
  
        div {
          margin-left: 20px;
        }
      }
    }
  
    .table-num {
      margin-left: 5px;
      background: #f0f0f0;
      width: 35px;
      border-radius: 5px;
    }
  }
  
  .button-box {
    margin-left: 30px;
    margin-bottom: 20px;
  
    .next-button {
      background-color: #eeeeee;
      color: #4c4c4c;
      height: 30px;
    }
  }
  </style>